package com.huike.controller;

import com.huike.core.domain.R;
import com.huike.core.page.TableDataInfo;
import com.huike.dto.ActivityDto;
import com.huike.dto.domain.Activity;
import com.huike.service.IActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clues/activity")
@Slf4j
public class ActivityController {
@Autowired
private IActivityService activityService;

/*分页查询活动*/
@GetMapping("/list")
    public TableDataInfo selectActivityList(@ModelAttribute ActivityDto activityDto){
    log.info("开始进行分页查询，controller");
return activityService.getActivityList(activityDto);

}
/*该方法为添加方法，活动那个只考虑一个一个添加，多个可考虑list*/
@PostMapping
    public R  addActivity(@RequestBody Activity activity){
activityService.addActivitySe(activity);
    return R.ok();


}
/*该方法为删除方法由于浏览器中未出现多个一起删除，多个用list*/
@DeleteMapping("/{id}")
    public R deleteActivity(@PathVariable Integer id){
    activityService.deleteActivitySe(id);
    return R.ok();
}
    /*删除方法*/
@PutMapping
    public R updateActivity(@RequestBody Activity activity){
activityService.updateActivitySe(activity);
    return R.ok();
}
    /*点进修改后的回显数据*/
@GetMapping("/{id}")
    public R<Activity> inquireActivity(@PathVariable Integer id){
    Activity activity = activityService.inquireActivitySe(id);

return R.ok(activity);

}
    /*根据活动类型线上活动和推广活动，回显活动个数*/
    @GetMapping("/listselect/{id}")
    public R<List<Activity>>   agreeActivityList(@PathVariable String id){
    log.info("接受到参数 {}", id);
        List<Activity> activities = activityService.agreeActivityListSe(id);
return R.ok(activities);

    }
}
